
import ply.lex as lex
import sys

keywords = {
	'input' : "INPUT",
	'high' : "VAR",
	'h' : "VAR",
	'l' : "VAR",
	'vol' : "VAR",
	}

tokens = [
	'NUMBER',
	'ID',
	'PLUS',
	'MINUS',
	'TIMES',
	'DIVIDE',
	'EXPORT',
	'ASSIGN',
	'LB',
	'RB',
	'COMMA',
	'GREATER',
	] + list(keywords.values())

t_PLUS    = r'\+'
t_MINUS   = r'-'
t_TIMES   = r'\*'
t_DIVIDE  = r'/'
t_EXPORT  = r':'
t_ASSIGN  = r'(:=)'
t_ignore  = r' \t\r;'
t_LB      = r'\('
t_RB      = r'\)'
t_COMMA   = r','
t_GREATER = r'>'

def t_NUMBER(t):
	r'[\+\-]?\d+(\.\d+)?'
	t.value = float(t.value)
	return t

def t_newline(t):
	r'\n+'
	t.lexer.lineno += len(t.value)

def t_error(t):
	print("ERROR:", t.value[0])
	t.lexer.skip(1)

def t_ID(t):
	r'\w[\w\d]*' 
	t.type = keywords.get(t.value.lower(), 'ID')
	return t

def main(): 
	if len(sys.argv) < 2:
		return
	lexer = lex.lex()
	data = open(sys.argv[1]).read()
	lexer.input(data)
	while True:
		tok = lexer.token()
		if not tok:
			break
		print(tok)

lexer = lex.lex()
